home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-12 | 2.2 KB | 45 lines | [TEXT/CCL2] |
- The little book about interfacing MCL and ThinkC
- (and in general, about interfacing two langages)
-
- Here are some thoughts that grew out of my trials and errors
- when I started interfacing MCL and ThinkC:
-
- When you decide to interface two langages that are not compatible
- in respect to data representation, you will have to make some choices.
-
- You can either allocate your data structures all in the first langage
- format, all in the second langage format, or a mixture of both.
-
- In either case, when one of the two langage needs to read data that
- was not allocated in its format, the code will be a little awkward
- and a little bit less efficient because of the necessary conversions.
-
- All this to say that the first step is a carefull planning of how you
- implement your data structures.
-
- Here are a few tips one the pros and cons of data structure allocation
- in both MCL and ThinkC:
-
- If you allocate structures in C (in the mac heap that is), you will
- have to do yourself all the job that Lisp normally does for you. i.e.
- allocating the memory, releasing it, etc... This is pretty painfull
- but it is the concession you have to make, if you want blazingly fast
- C code. Also this approach lets you write nice C code since the data
- is in a format that it understands readily. Another drawback of this
- approach is that your data is not typed anymore, so the Lisp environment
- wont be abble to display it intelligently. i.e. All your data will
- look like #<A Mac Zone Pointer Size 12 #x7DDDC4> which doesnt make
- debugging very easy...
-
- Allocating your structures in Lisp gives you all the benefits of Lisp
- but makes your C code harder to write and somewhat less efficient. But
- even then your C code should run faster than the Lisp equivalent because
- it wont need to do any type checking, and will also run in constant memory
- so it won't garbage collect.
-
- The ideal solution is probably to really well isolate the computationally
- expansive parts of your code and transfer only those in C. Since the C code
- you define is not user interruptible, it is best to define small
- functions rather that large ones (so Lisp gets a lot of occasions to
- manage user events).
-